﻿using SuperX.Common.Abstract;
using SuperX.Common.Helper;
using SuperX.Common.Respository;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace SuperX.Common
{
    //
    [JsonConverter(typeof(BasicJsonConverter<ITag>))]
    public interface ITag : IBasicObject, IJsonSerialize, IDisposable, ICloneable
    {
        //
        TagType TagType { get; set; }

        object DefaultValue { get; set; }

        /// <summary>
        /// 初始值
        /// </summary>
        object InitValue { get; set; }

        // 值
        object Value { get; set; }

        // 时间戳
        [MessageJsonInclude]
        [JsonIgnore]
        DateTime TimeStamp { get; set; }

        // 质量戳
        [MessageJsonInclude]
        [JsonIgnore]
        QUALITIES Quality { get; set; }

        // 只读
        bool IsReadOnly { get; set; }

        // 值类型
        [JsonIgnore]
        Type ValueType { get; set; }

        event EventHandler<TagChangingEventArgs> ValueChanging;

        event EventHandler<TagChangedEventArgs> ValueChanged;
    }

    public interface ITag<T> : ITag where T : IComparable
    {
        new T Value { get; set; }

        new T InitValue { get; set; }

        void UpdateTagValue(T value);

        void UpdateTagValue(T value, ushort qualityStamp, DateTime timeStamp, string updateSourceName);

        void WriteTagValue(T value);

        void WriteTagValue(T value, ushort qualityStamp, DateTime timeStamp);
    }
}